<?php

header("Content-type:text/html;charset=utf-8");



$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "bbv";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // 开始一个事务->做保存点->操作->可以回滚,可以提交,没有问题,就是提交,有问题就回滚,记得MYSQL学习 转账的例子

    // 开始事务
    $conn->beginTransaction();

    // sql语句
    $conn->exec("insert into bbv(firstName,lastName,email)
    values('JoIn','Doe','Join@email.com')");

    $conn->exec("insert into bbv(firstName,lastName,email)
    values('Mary','moe','mary@email.com')");

    $conn->exec("insert into bbv(firstName,lastName,email)
    values('Julie','jiy''jiy@email.com')");

    // 提交事务,感觉像git
    $conn->commit();

    echo "已经插入多条数据";
} catch (PDOException $e) {
    // 如果执行中的某一个环节失败,则会滚事务
    $conn->rollback();
    echo $sql . "" . $e->getMessage();
}
$conn = null;





